<template>
  <div class="sousuo">
    <div class="sousuo1">
      <p>人员姓名:</p>
      <el-input v-model="search" size="large" placeholder="Type to search" />
    </div>
    <div class="sousuo2">
      <p>部门选择:</p>
      <el-input v-model="search1" size="large" placeholder="Type to search" />
    </div>
  </div>
  <el-table :data="custom" style="width: 100%" :cell-style="cellStyle">
    <el-table-column fixed prop="cShorts" label="商品名称" width="200" />
    <el-table-column prop="cName" label="报修人员" width="200" />
    <el-table-column prop="cPhone" label="联系方式" width="200" />
    <el-table-column prop="addr" label="人员地址" width="200" />
    <el-table-column prop="cNow" label="状态" width="200" />
    <el-table-column prop="cData" label="时间" width="200" />
    <el-table-column label="操作" prop="cmake" width="200">
      <template #default="scope">
        <el-button link type="primary" text @click="openVn(scope.row)">
          派遣</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <div>
    <el-dialog v-model="dialogTableVisible" title="派遣人员">
      <el-table
        ref="multipleTableRef"
        :data="gridData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="goodsName" label="姓名" width="200">
        </el-table-column>
        <el-table-column prop="goodsPhone" label="联系方式" width="200" />
        <el-table-column
          prop="goodsStatus"
          label="工作状态"
          show-overflow-tooltip
        />
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button
            type="primary"
            @click="confirm"
            :disabled="check"
            :plain="true"
            >确认派遣</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import {
  ref,
  onMounted,
  onBeforeUnmount,
  computed,
  watch,
  nextTick,
  h,
} from "vue";
import dayjs from "dayjs";
import { indexApi } from "@/api/api";
import "@/mock/index";
import { useStore } from "vuex";
import { ElMessage } from "element-plus";
const store = useStore();
interface User {
  cNow: string;
  row: any;
  rowIndex: string;
  column: any;
  columnIndex: number;
  value: any;
}
const search = ref<string>("");
const search1 = ref<string>("");
let stateNow = ref<any>();
let custom = ref<any>();

let cellStyle = ({ row, rowIndex, column, columnIndex }: User) => {
  let cellstyle: any;
  if (column.label == "状态" && columnIndex == 4 && row.cNow == "未派遣") {
    return { color: "red" };
  }
  if (column.label == "状态" && columnIndex == 4 && row.cNow == "已派遣") {
    // dialogTableVisible.value = false;
    return { color: "green" };
  }
};
// 派遣人员
let gridData = ref<any>([
  {
    date: "2016-05-03",
    name: "John Smith",
    address: "No.1518,  Jinshajiang Road, Putuo District",
  },
]);
onMounted(async () => {
  store.dispatch("getCustom").then((res) => {
    console.log(res);

    custom.value = res.data;
  });
  // 派遣人员
  const list = await indexApi({ data: "data" });
  gridData.value = list.data.splice(0, 6);
});
let dialogTableVisible = ref<boolean>(false);

// 是否派遣
const openVn = (row: any) => {
  console.log(row);
  stateNow.value = row.cName;
  if (row.cNow == "未派遣") {
    dialogTableVisible.value = true;
  } else {
    dialogTableVisible.value = false;
  }
  if (row.cNow == "已派遣") {
    ElMessage({
      message: h("p", null, [
        h("span", null, "已派遣 "),
        h("i", { style: "color: teal font-size:24px" }),
      ]),
    });
  }
};
// 确认派遣
const outerVisible = ref(false);
const confirm = (scope: any) => {
  custom.value = custom.value.filter((va: any, index: any) => {
    if (va.cName == stateNow.value) {
      console.log("11");

      va.cNow = "已派遣";
    }
    return va;
  });
  ElMessage({
    message: h("p", null, [h("i", { style: "color: green" }, "已派遣")]),
  });
  dialogTableVisible.value = false;
};
// 勾选
let check = ref<any>(true);
// 多选
const multipleSelection = ref<User[]>([]);
const handleSelectionChange = (val: User[]) => {
  multipleSelection.value = val;
  if (multipleSelection.value.length === 0) {
    check.value = true;
  } else {
    check.value = false;
  }
};
</script>
<style lang="less" scoped>
.sousuo {
  display: flex;
  margin-bottom: 4px;
  margin-top: 10px;

  .sousuo1 {
    display: flex;

    p {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      width: 120px;
    }

    margin-right: 60px;
  }

  .sousuo2 {
    display: flex;

    p {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      width: 120px;
    }
  }
}
.el-input__inner {
  margin-bottom: 20px;
}
</style>
